import Vue from 'vue'
import Vuex from 'vuex'
import request from '../common/SDK/request/request.js'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {}
	},
	mutations: {
		login(state,token) {
			state.hasLogin = true;
			console.log(state.hasLogin)
			// state.userInfo = provider;
			uni.setStorage({//缓存用户登陆状态
				key: 'userToken',  
				data: {
					"token":token,
					"time":new Date()
				}
			}) 
		},
		logout(state) {
			state.hasLogin = false;
			// state.userInfo = {};
			uni.removeStorage({  
                key: 'userToken'  
            })
		},
		timeDiff(state,time){
			var dateEnd = new Date();//获取当前时间
			let diff = dateEnd.getTime()-new Date(time).getTime();
			return diff/1000;
		},
		updateUserInfo(state,newVal){
			state.userInfo = newVal;
		}
	},
	actions: {
	
	}
})

export default store
